var upas = new Array();
var uprs = new Array();

function setProgressDivProperties(panelDiv, progressDiv)
{
	var upa = document.getElementById(panelDiv);
	var upr = document.getElementById(progressDiv);
	
	upas[progressDiv] = panelDiv;
	uprs[panelDiv] = progressDiv;

	var upaPos = findPos(upa);

	upr.style.width = upa.offsetWidth + 'px';
	upr.style.height = upa.offsetHeight + 'px';
	upr.style.left = upaPos[0] + 'px';
	upr.style.top = upaPos[1] + 'px';
}

function panelsProgressBeginRequestHandler(sender, args)
{
	postbackElement = args.get_postBackElement();
	window.status = 'Panel requests started.';
}

function panelsProgessPageLoadedEventHandler(sender, args)
{
	var updatedPanels = args.get_panelsUpdated();
    if (typeof(postbackElement) === "undefined")
    {
		return;
	}
	for (i = 0; i < updatedPanels.length; i++)
	{
		var id = updatedPanels[i].id;
		setProgressDivProperties(id, uprs[id]);
	}

	window.status = 'Panels loaded.';
}

function getScreenSize()
{
	var myWidth = 0;
	var myHeight = 0;

	if (typeof(window.innerWidth) == 'number')
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else
	if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else
	if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	return [myWidth, myHeight];
}

function getScrollXY()
{
	var scrOfX = 0;
	var scrOfY = 0;
	
	if (typeof(window.pageYOffset) == 'number')
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else
	if (document.body && (document.body.scrollLeft || document.body.scrollTop ))
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else
	if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX, scrOfY];
}

function findPos(obj)
{
	var curLeft = 0;
	var curTop = 0;
	
	if (obj.offsetParent)
	{
		curLeft = obj.offsetLeft
		curTop = obj.offsetTop
		
		while (obj = obj.offsetParent)
		{
			curLeft += obj.offsetLeft
			curTop += obj.offsetTop
		}
	}
	
	return [curLeft, curTop];
}
